import request from './request.js'
import baseUrl from './baseUrl.js'
const common = {
	upload(file, options = {}) {
		return new Promise((resolve, reject) => {
			uni.uploadFile({
				url: `${baseUrl}/api/v1/pub/upload`,
				filePath: file,
				name: 'file',
				fileType: 'image',
				...options,
				success: (res) => {
					let data = JSON.parse(res.data)
					if (data.code === 200) {
						resolve(data)
					} else {
						uni.showToast({
							title: data.msg,
							icon: 'none'
						})
						reject()
					}
				},
				fail: err => {
					uni.showToast({
						title: '上传失败, 请重新上传',
						icon: "none",
						duration: 2000
					})
					reject()
				}
			})
		})
	
	},
	revenueRule() {
		return request.get('/api/v1/pub/getRebateRule')
	},
	
	revenueRule2() {
		return request.get('/api/v1/pub/revenueRule')
	},
}
export default common